<?php
$query = mysql_query("SELECT * FROM todo");
$main .= '<h2>Todo list</h2>';
if($_GET['plus']) {
	if($check->isAdmin()) {
		$id = $_GET['plus'];
		mysql_query("UPDATE todo SET percent = percent + 5 WHERE id = '$id'");
		header("Location: ?page=todo");
		exit;
	} else {
		$main = 'You\'re not admin!';
	}
}
if($_GET['minus']) {
	if($check->isAdmin()) {
		$id = $_GET['minus'];
		mysql_query("UPDATE todo SET percent = percent - 5 WHERE id = '$id'");
		header("Location: ?page=todo");
		exit;
	} else {
		$main = 'You\'re not admin!';
	}
}
if($_GET['low']) {
	if($check->isAdmin()) {
		$id = $_GET['low'];
		mysql_query("UPDATE todo SET priority = 'LOW' WHERE id = '$id'");
		header("Location: ?page=todo");
		exit;
	} else {
		$main = 'You\'re not admin!';
	}
}
if($_GET['medium']) {
	if($check->isAdmin()) {
		$id = $_GET['medium'];
		mysql_query("UPDATE todo SET priority = 'MEDIUM' WHERE id = '$id'");
		header("Location: ?page=todo");
		exit;
	} else {
		$main = 'You\'re not admin!';
	}
}
if($_GET['high']) {
	if($check->isAdmin()) {
		$id = $_GET['high'];
		mysql_query("UPDATE todo SET priority = 'HIGH' WHERE id = '$id'");
		header("Location: ?page=todo");
		exit;
	} else {
		$main = 'You\'re not admin!';
	}
}
if($_GET['delete']) {
	if($check->isAdmin()) {
		$id = $_GET['delete'];
		mysql_query("DELETE FROM todo WHERE id = '$id'");
		header("Location: ?page=todo");
		exit;
	} else {
		$main = 'You\'re not admin!';
	}
}
if(mysql_num_rows($query) < 1) {
	$main .= 'There\'s nothing to do! ';
	if($check->isAdmin()) 
		$main .= '<br /><a href="?page=addtodo">Click here to add!</a>';
} else {
	while ($row = mysql_fetch_assoc($query))
	{
		$main .= '
			<ul>
				<li>To do: '.$row['todo'].' - '.$row['percent'].'% done - Priority: '.$row['priority'].''; 
				if($check->isAdmin()) { $main .= '<br /><a href="?page=todo&plus='.$row['id'].'">[+5%]</a><a href="?page=todo&minus='.$row['id'].'">[-5%]</a><a href="?page=todo&low='.$row['id'].'">[LOW]</a><a href="?page=todo&medium='.$row['id'].'">[MEDIUM]</a><a href="?page=todo&high='.$row['id'].'">[HIGH]</a> <a href="?page=todo&delete='.$row['id'].'">[x]</a>'; } $main .= '
				</li>
			</ul>
			';
				
	}
}

?>